package asteroids.model.programs.Expression;

public class VariableEquality extends VariableComparison {

	public VariableEquality(int line, int column, Expression e1, Expression e2)
			throws IllegalArgumentException {
		super(line, column, e1, e2);
	}

	@Override
	public boolean getBoolean() {
		if(getFirstExpression().getType() == null){
			throw new IllegalStateException("getType of first expression is null");
		}
		if(getSecondExpression().getType() == null){
			throw new IllegalStateException("getType of second expression is null");
		}
		if(getFirstExpression().getType().getType() != getSecondExpression().getType().getType())
			throw new IllegalStateException("The given expressions have different type");
		switch(getFirstExpression().getType().getType()){
		case BOOLEAN:
			return ((IBooleanExpression)getFirstExpression()).getBoolean() == ((IBooleanExpression) getSecondExpression()).getBoolean();
		case DOUBLE:
			return ((IDoubleExpression)getFirstExpression()).getValue() == ((IDoubleExpression)getSecondExpression()).getValue();
		case ENTITY:
			return ((IEntityExpression)getFirstExpression()).getEntity() == ((IEntityExpression)getSecondExpression()).getEntity();
		default:
			throw new IllegalStateException("Housten we have a problem");
		
		}
	}

}
